home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* WAKEUP main line *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991 by H. Roy Engehausen. All rights *)
- (* reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- UNIT BBWAKEUP;
-
- INTERFACE
-
- PROCEDURE wakeup;
-
- VAR
- wakeup_shut_sw : BOOLEAN;
-
- IMPLEMENTATION
-
- USES
- DOS,
- bbdummy,
- bbmess,
- bbmisci,
- bbmisc5,
- bbsdata,
- bbsema2,
- bbstr,
- bbtime,
- bbucmd,
- bbwin;
-
- PROCEDURE wakeup;
-
- VAR
- date_ok : BOOLEAN;
- did_today : BOOLEAN;
- event_time : LONGINT;
- i : BYTE;
- last_time : LONGINT;
- line_buffer : STRING;
- line_no : WORD;
- line_no_str : STRING[5];
- midnight : LONGINT;
- small_time : LONGINT;
- wakeup_count : WORD;
- wakeup_in : TEXT;
- wakeup_out : TEXT;
- wakeup_temp : STRING;
-
- {$I BBWAKEPL}
-
- PROCEDURE wakeup_cleanup;
-
- VAR
- t : LONGINT;
-
- BEGIN;
-
- {$I-}
- CLOSE(wakeup_in);
- CLOSE(wakeup_out);
- {$I+}
-
- t := current_day_time + small_time;
-
- IF wakeup_time < t THEN
- wakeup_time := t;
-
- END;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize *)
- (*-----------------------------------------------------------------------*)
-
- active_port := @dummy_port;
- active_tcb^.tcb_port := @dummy_port;
-
- active_tcb^.port_chan_s := 'WK';
- active_tcb^.error_sw := FALSE;
-
- small_time := opt_block.wakeup_intervl + 1;
- small_time := small_time DIV secs_per_tick;
-
- (*-----------------------------------------------------------------------*)
- (* Tell user we are running *)
- (*-----------------------------------------------------------------------*)
-
- send_tnc_data_str('WAKEUP processing started' + cr);
-
- (*-----------------------------------------------------------------------*)
- (* Set default wakeup time to midnight *)
- (*-----------------------------------------------------------------------*)
-
- wakeup_time := last_midnight + ticks_per_day;
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Open wakeup input file *)
- (*-----------------------------------------------------------------------*)
-
- ASSIGN(wakeup_in, opt_block.wakeup_fn);
-
- {$I-}
- RESET(wakeup_in);
- i := IORESULT;
- {$I+}
-
- (*-----------------------------------------------------------------------*)
- (* Free the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Handle open errors *)
- (*-----------------------------------------------------------------------*)
-
- IF i = 2 THEN
- BEGIN;
- send_tnc_data_str('WAKEUP file not found' + cr);
- EXIT;
- END;
-
- IF i <> 0 THEN
- BEGIN;
- send_tnc_data_str('I/O error on WAKEUP input file' + cr);
- send_tnc_data_str(dos_err_message(i) + cr);
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Open wakeup output file *)
- (* Note: The last two variables on the FSPLIT are "don't care" *)
- (*-----------------------------------------------------------------------*)
-
- FSPLIT(opt_block.wakeup_fn, wakeup_temp, line_buffer, line_no_str);
-
- wakeup_temp := wakeup_temp + 'WAKEUP.TMP';
-
- ASSIGN(wakeup_out, wakeup_temp);
-
- {$I-}
- REWRITE(wakeup_out);
- i := IORESULT;
- {$I+}
-
- (*-----------------------------------------------------------------------*)
- (* Free the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Handle open errors *)
- (*-----------------------------------------------------------------------*)
-
- IF i <> 0 THEN
- BEGIN;
- send_tnc_data_str('I/O error on WAKEUP output file' + cr);
- send_tnc_data_str(dos_err_message(i));
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Processing loop *)
- (*-----------------------------------------------------------------------*)
-
- line_no := 0;
- wakeup_did_something := FALSE;
-
- WHILE NOT EOF(wakeup_in) DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Bump line number and prepare error message text in case it is *)
- (* needed. *)
- (*-------------------------------------------------------------------*)
-
- INC(line_no);
- STR(line_no, line_no_str);
- line_no_str := line_no_str + cr;
-
- (*-------------------------------------------------------------------*)
- (* Read a line *)
- (*-------------------------------------------------------------------*)
-
- READLN(wakeup_in, line_buffer);
-
- (*-------------------------------------------------------------------*)
- (* Check for null lines and comments *)
- (*-------------------------------------------------------------------*)
-
- IF (LENGTH(line_buffer) > 0)
- AND (line_buffer[1] <> '*')
- AND (line_buffer[1] <> ';') THEN
- BEGIN;
-
- (*---------------------------------------------------------------*)
- (* Upper case the thing *)
- (*---------------------------------------------------------------*)
-
- upcase_str_var(line_buffer);
-
- (*---------------------------------------------------------------*)
- (* Process the last date time and action date time *)
- (*---------------------------------------------------------------*)
-
- process_line;
-
- (*---------------------------------------------------------------*)
- (* Do we need action? *)
- (*---------------------------------------------------------------*)
-
- IF event_time < current_day_time THEN
- BEGIN;
-
- (*-----------------------------------------------------------*)
- (* Action needed. We will want to wake up a minute from now *)
- (*-----------------------------------------------------------*)
-
- wakeup_time := current_day_time + small_time;
-
- (*-----------------------------------------------------------*)
- (* We only do one action per wakeup *)
- (*-----------------------------------------------------------*)
-
- IF NOT wakeup_did_something THEN
- BEGIN;
-
- (*-------------------------------------------------------*)
- (* Assume we did it *)
- (*-------------------------------------------------------*)
-
- wakeup_did_something := TRUE;
-
- (*-------------------------------------------------------*)
- (* First action this wakeup cycle. So do it *)
- (*-------------------------------------------------------*)
-
- wakeup_temp := subword(@line_buffer, 3, 0);
-
- send_tnc_data_str('Executing WAKEUP -- Line #'
- + line_no_str);
- send_tnc_data_str('Command: ' + wakeup_temp + cr);
-
- user_command(wakeup_temp);
-
- (*-------------------------------------------------------*)
- (* Set last time so we know we did it *)
- (*-------------------------------------------------------*)
-
- IF wakeup_did_something THEN
- last_time := current_day_time;
-
- END
-
- ELSE
-
- (*---------------------------------------------------------*)
- (* Action needed later. Wakeup one minute *)
- (*---------------------------------------------------------*)
-
- wakeup_time := current_day_time + small_time;
-
- END
- ELSE
- BEGIN;
-
- (*-----------------------------------------------------------*)
- (* Not time for this action. See if we need to move up the *)
- (* wakeup time *)
- (*-----------------------------------------------------------*)
-
- IF event_time < wakeup_time THEN
- wakeup_time := event_time;
-
- END;
-
- (*---------------------------------------------------------------*)
- (* Prepare the output buffer *)
- (*---------------------------------------------------------------*)
-
- line_buffer := time_str(last_time, TRUE) + ' ' + line_buffer;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Write the line back to the WAKEUP file *)
- (*-------------------------------------------------------------------*)
-
- WRITELN(wakeup_out, line_buffer);
-
- END; (*----- End loop reading wakeup file -----------------------------*)
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Clean things up. *)
- (*-----------------------------------------------------------------------*)
-
- wakeup_cleanup;
-
- (*-----------------------------------------------------------------------*)
- (* Erase the old file and rename the new one to the right name *)
- (*-----------------------------------------------------------------------*)
-
- ERASE(wakeup_in);
- RENAME(wakeup_out, opt_block.wakeup_fn);
-
- (*-----------------------------------------------------------------------*)
- (* Free the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Tell user we are done *)
- (*-----------------------------------------------------------------------*)
-
- send_tnc_data_str('WAKEUP processing ended -- Next wakeup at '
- + time_str(wakeup_time, TRUE) + cr);
-
- send_flush;
-
- IF wakeup_shut_sw THEN
- shutdown_bbs;
-
- EXIT;
-
- END;
-
- END.